home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / slang / slang.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  34.8 KB  |  1,089 lines

  1. #ifndef DAVIS_SLANG_H_
  2. #define DAVIS_SLANG_H_
  3. /* Copyright (c) 1992, 1995 John E. Davis
  4.  * All rights reserved.
  5.  * 
  6.  * You may distribute under the terms of either the GNU General Public
  7.  * License or the Perl Artistic License.
  8.  */
  9.  
  10. /* Midnight Commander change: some Unices do not define this, and slang
  11.  * requires it:
  12.  */
  13.  
  14. #ifndef unix
  15. #    define unix
  16. #endif
  17.  
  18. #define SLANG_VERSION 9920
  19. #if defined(__WATCOMC__) && !defined(__QNX__)
  20. #include <slconfig.h>
  21. #endif
  22.  
  23. /* Configure the Linux unicode support */
  24. #ifdef linux
  25. # include <sys/types.h>
  26. # include <linux/kd.h>
  27. # ifdef GIO_UNIMAP
  28. # define linux_unicode
  29. # endif
  30. #endif
  31.  
  32.  
  33.  
  34. #ifdef FLOAT_TYPE
  35. #ifndef USE_DOUBLE
  36. #define USE_DOUBLE
  37. #endif
  38. #endif
  39.  
  40.  
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44.  
  45. /* ---------------------------- Generic Macros ----------------------------- */
  46.  
  47. /*  __SC__ is defined for Symantec C++
  48.    DOS386 is defined for -mx memory model, 32 bit DOS extender. */
  49.  
  50. #ifdef VOID
  51. #undef VOID
  52. #endif
  53.  
  54. #if defined(msdos) && !defined(DOS386) & !defined(__WIN32__)
  55. #  ifdef __SC__
  56. #    include <dos.h>
  57. #  endif
  58. #  define VOID void
  59. #  include <alloc.h>
  60. #else
  61. #  ifndef NO_STDLIB_H
  62. #    include <stdlib.h>
  63. #  endif
  64. #  ifdef __cplusplus
  65. #    define VOID void
  66. #  else
  67. #    define VOID unsigned char
  68. #  endif
  69. #endif
  70.    
  71. #ifndef MALLOC_DEBUG
  72. #if defined(msdos) && !defined(DOS386)
  73. #  define SLFREE(buf)  farfree((void far *)(buf))
  74. #  define SLMALLOC(x) farmalloc((unsigned long) (x))
  75. #  define SLREALLOC(buf, n) farrealloc((void far *) (buf), (unsigned long) (n))
  76. #  define SLCALLOC(n, m) farcalloc((unsigned long) (n), (unsigned long) (m))
  77. #else
  78. #  if defined(VMS) && !defined(__DECC)
  79. #    define SLFREE VAXC$FREE_OPT
  80. #    define SLMALLOC VAXC$MALLOC_OPT
  81. #    define SLREALLOC VAXC$REALLOC_OPT
  82. #    define SLCALLOC VAXC$CALLOC_OPT
  83. #  else
  84. #    define SLFREE(x) free((char *)(x))
  85. #    define SLMALLOC malloc
  86. #ifdef __cplusplus
  87. #    define SLREALLOC(p,n) realloc((malloc_t) (p), n)
  88. #else
  89. #    define SLREALLOC realloc
  90. #endif
  91. #    define SLCALLOC calloc
  92. #  endif
  93. #endif
  94.  
  95. #else
  96.    /* MALLOC_DEBUG */
  97. # define SLMALLOC(x) SLdebug_malloc((unsigned long) (x))
  98. # define SLFREE(x) SLdebug_free((unsigned char *)(x))
  99. # define SLCALLOC(n, m) SLdebug_calloc((unsigned long) (n), (unsigned long)(m))
  100. # define SLREALLOC(p, x) SLdebug_realloc((unsigned char *)(p), (unsigned long)(x))
  101.  
  102.    extern unsigned char *SLdebug_malloc (unsigned long);
  103.    extern unsigned char *SLdebug_calloc (unsigned long, unsigned long);
  104.    extern unsigned char *SLdebug_realloc (unsigned char *, unsigned long);
  105.    extern void SLdebug_free (unsigned char *);
  106.    extern void SLmalloc_dump_statistics (void);
  107.    
  108. #endif /* MALLOC_DEBUG */
  109.  
  110. /* If your compiler does not have memory.h, ignore this line */
  111. #if !defined(VMS) && !defined(__WATCOMC__)
  112. #include <memory.h>
  113. #endif 
  114.  
  115. #ifdef HAS_MEMSET
  116. #define MEMSET memset
  117. #else 
  118. #define MEMSET jed_memset
  119. extern void jed_memset(char *, char, int);
  120. #endif
  121.  
  122. #ifdef HAS_MEMCHR
  123. #define MEMCHR memchr
  124. #else 
  125. #define MEMCHR jed_memchr
  126. extern char *jed_memchr(register char *, register char, register int);
  127. #endif
  128.  
  129. #ifdef HAS_MEMCPY
  130. #define MEMCPY memcpy
  131. #else
  132. #define MEMCPY jed_memcpy
  133. extern char *jed_memcpy(char *, char *, int);
  134. #endif
  135.  
  136. #ifdef HAS_MEMCMP
  137. #define MEMCMP memcmp
  138. #else
  139. #define MEMCMP jed_memcmp
  140. extern int jed_memcmp(char *, char *, int);
  141. #endif
  142.  
  143. /* -------------------  S-Lang Stuff -------------------------------*/
  144.  
  145. #define FLOAT double
  146.  
  147.  
  148. #define SLANG_MAX_NAME_LEN 30
  149. /* maximum length of an identifier */
  150. /* first char in identifiers is the hash */
  151.  
  152. typedef struct SLang_Name_Type
  153.   {
  154. #ifdef SLANG_STATS
  155.      int n;                   /* number of times referenced */
  156. #endif
  157.      char name[SLANG_MAX_NAME_LEN + 2]; /* [0] is hash */
  158.  
  159.      unsigned char sub_type;
  160.      unsigned char main_type;
  161.      long addr;
  162.   }
  163. SLang_Name_Type;
  164.  
  165.  
  166. typedef struct SLang_Load_Type
  167. {
  168.    long name;                   /* file name, string address, ... */
  169.    long handle;                   /* FILE *, string address, etc... */
  170.    
  171.    char *ptr;                   /* input pointer to next line in object
  172.                     * to be read. 
  173.                     */
  174.    /* Things below here are used by S-Lang. */
  175.    int type;                   /* 'F' = file, 'S' = String, etc.. */
  176.    char *buf;                   /* buffer for file, etc... */
  177.    char *(*read)(struct SLang_Load_Type *);   /* function to call to read obj */
  178.    int n;                   /* line number, etc... */
  179.    char token[256];               /* token to be parsed */
  180.    int ofs;                   /* offset from buf where last read
  181.                     * took place 
  182.                     */
  183.    int top_level;               /* 1 if at top level of parsing */
  184. } SLang_Load_Type;
  185.  
  186. #ifndef NO_PROTOTYPES 
  187. # define _PROTO(x) x
  188. #else
  189. # define _PROTO(x) ()
  190. #endif
  191.  
  192. typedef struct SL_OOBinary_Type
  193. {
  194.    unsigned char sub_type;           /* partner type for binary op */
  195.    
  196.    /* The function take the binary op as first argument, the operand types
  197.     * form the second and third parameters and the last two parameters are 
  198.     * pointers to the objects themselves.  It is up to the function to push
  199.     * the result on the stack.  It must return 1 if it handled the operation 
  200.     * return zero if the operation is not defined.
  201.     */
  202.    int (*binary_function)_PROTO((int, unsigned char, unsigned char, 
  203.                   VOID *, VOID *));
  204.  
  205.    struct SL_OOBinary_Type *next;
  206. }
  207. SL_OOBinary_Type;
  208.  
  209. typedef struct
  210. {
  211.    /* Methods */
  212.    void (*destroy)_PROTO((VOID *));
  213.    /* called to delete/free the object */
  214.    char *(*string)_PROTO((VOID *));
  215.    /* returns a string representation of the object */
  216.    int (*unary_function)_PROTO((int, unsigned char, VOID *));
  217.    /* unary operation function */
  218.    SL_OOBinary_Type *binary_ops;
  219.    
  220.    int (*copy_function)_PROTO((unsigned char, VOID *));
  221.    /* This function is called do make a copy of the object */
  222. } SLang_Class_Type;
  223.  
  224. extern SLang_Class_Type *SLang_Registered_Types[256];
  225.    
  226. typedef struct
  227. {
  228.    unsigned char main_type;           /* SLANG_RVARIABLE, etc.. */
  229.    unsigned char sub_type;           /* int, string, etc... */
  230.    long *obj;                   /* address of user structure */
  231.  
  232.    /* Everything below is considered private */
  233.    unsigned int count;               /* number of references */
  234. }
  235. SLuser_Object_Type;
  236.  
  237.    
  238.   extern volatile int SLang_Error;
  239.   /* Non zero if error occurs.  Must be reset to zero to continue. */
  240.  
  241.   extern int SLang_Traceback;
  242.   /* If non-zero, dump an S-Lang traceback upon error.  Available as 
  243.      _traceback in S-Lang. */
  244.  
  245.   extern char *SLang_User_Prompt;
  246.   /* Prompt to use when reading from stdin */
  247.   extern int SLang_Version;
  248.  
  249.   extern void (*SLang_Error_Routine)(char *);
  250.   /* Pointer to application dependent error messaging routine.  By default,
  251.      messages are displayed on stderr. */
  252.  
  253.   extern void (*SLang_Exit_Error_Hook)(char *);
  254.   extern void SLang_exit_error (char *);
  255.   extern void (*SLang_Dump_Routine)(char *);
  256.   /* Called if S-Lang traceback is enabled as well as other debugging 
  257.      routines (e.g., trace).  By default, these messages go to stderr. */
  258.   
  259.   extern void (*SLang_Interrupt)(void);
  260.   /* function to call whenever inner interpreter is entered.  This is 
  261.      a good place to set SLang_Error to USER_BREAK. */
  262.  
  263.   extern void (*SLang_User_Clear_Error)(void);
  264.   /* function that gets called when '_clear_error' is called. */
  265.   extern int (*SLang_User_Open_Slang_Object)(SLang_Load_Type *); 
  266.   extern int (*SLang_User_Close_Slang_Object)(SLang_Load_Type *);
  267.   /* user defined loading routines. */
  268.  
  269.  
  270.   /* If non null, these call C functions before and after a slang function. */
  271.   extern void (*SLang_Enter_Function)(char *);
  272.   extern void (*SLang_Exit_Function)(char *);
  273.  
  274.  
  275. /* Functions: */
  276.  
  277.    extern int init_SLang(void);   
  278.    /* This function is mandatory and must be called by all applications */
  279.    extern int init_SLfiles(void);
  280.    /* called if fputs, fgets, etc are need in S-Lang */
  281.    extern int init_SLmath(void);
  282.    /* called if math functions sin, cos, etc... are needed. */
  283.  
  284.    extern int init_SLunix(void);
  285.    /* unix system functions chmod, stat, etc... */
  286.  
  287.    extern int init_SLmatrix(void);
  288.    
  289.    extern int SLang_add_table(SLang_Name_Type *, char *);
  290.    /* add application dependent function table p1 to S-Lang.  A name p2 less 
  291.     *  than 32 characters must also be supplied.      
  292.     * Returns 0 upon failure or 1 upon success. */
  293.  
  294.    extern int SLang_add_global_variable (char *);
  295.    extern int SLang_load_object(SLang_Load_Type *);
  296.    extern int SLang_load_file(char *);
  297.    /* Load a file of S-Lang code for interpreting.  If the parameter is
  298.    NULL, input comes from stdin. */
  299.  
  300.    extern void SLang_restart(int);
  301.    /* should be called if an error occurs.  If the passed integer is
  302.     * non-zero, items are popped off the stack; otherwise, the stack is 
  303.     * left intact.  Any time the stack is believed to be trashed, this routine
  304.     * should be called with a non-zero argument (e.g., if setjmp/longjmp is
  305.     * called). */ 
  306.  
  307.    extern void SLang_byte_compile_file(char *, int *);
  308.    /* takes a file of S-Lang code and ``byte-compiles'' it for faster
  309.     * loading.  The new filename is equivalent to the old except that a `c' is
  310.     * appended to the name.  (e.g., init.sl --> init.slc).  If the second 
  311.     * parameter is non-zero, preprocess the file only.
  312.     */
  313.  
  314.    extern void SLang_autoload(char *, char *);
  315.    /* Automatically load S-Lang function p1 from file p2.  This function
  316.       is also available via S-Lang */
  317.    
  318.    extern char *SLang_load_string(char *);
  319.    /* Like SLang_load_file except input is from a null terminated string. */
  320.    
  321.    extern void SLang_do_pop(void);
  322.    /* pops item off stack and frees any memory associated with it */
  323.    
  324.    extern int SLang_pop_integer(int *);
  325.    /* pops integer *p0 from the stack.  Returns 0 upon success and non-zero
  326.     * if the stack is empty or a type mismatch occurs, setting SLang_Error.
  327.     */
  328.  
  329.    extern int SLang_pop_string(char **, int *);
  330.    /* pops string *p0 from stack.  If *p1 is non-zero, the string must be
  331.     * freed after its use.  DO NOT FREE p0 if *p1 IS ZERO! Returns 0 upon
  332.     * success */
  333.       
  334.    extern int SLang_pop_float(FLOAT *, int *, int *);
  335.    /* Pops float *p1 from stack.  If *p3 is non-zero, *p1 was derived
  336.       from the integer *p2. Returns zero upon success. */
  337.       
  338.    extern SLuser_Object_Type *SLang_pop_user_object (unsigned char);
  339.    extern void SLang_free_user_object (SLuser_Object_Type *);
  340.    extern void SLang_push_user_object (SLuser_Object_Type *);
  341.    extern SLuser_Object_Type *SLang_create_user_object (unsigned char);
  342.    
  343.    extern int SLang_add_unary_op (unsigned char, VOID *);
  344.    extern int SLang_add_binary_op (unsigned char, unsigned char, VOID *);
  345.    extern int SLang_register_class (unsigned char, VOID *, VOID *);
  346.    extern int SLang_add_copy_operation (unsigned char, VOID *);
  347.  
  348.    extern long *SLang_pop_pointer(unsigned char *, unsigned char *, int *);
  349.    /* Returns a pointer to object of type *p1,*p2 on top of stack. 
  350.       If *p3 is non-zero, the Object must be freed after use. */
  351.  
  352.  
  353.    extern void SLang_push_float(FLOAT);
  354.    /* Push Float onto stack */
  355.  
  356.    extern void SLang_push_string(char *);
  357.    /* Push string p1 onto stack */
  358.    
  359.    extern void SLang_push_integer(int);
  360.    /* push integer p1 on stack */
  361.  
  362.    extern void SLang_push_malloced_string(char *);
  363.    /* The normal SLang_push_string mallocs space for the string.  This one
  364.       does not.  DO NOT FREE IT IF YOU USE THIS ROUTINE */
  365.  
  366.    extern int SLang_is_defined(char *);
  367.    /* Return non-zero is p1 is defined otherwise returns 0. */
  368.    
  369.    extern int SLang_run_hooks(char *, char *, char *);
  370.    /* calls S-Lang function p1 pushing strings p2 and p3 onto the stack
  371.     * first.  If either string is NULL, it is not pushed. If p1 is not
  372.     * defined, 0 is returned. */
  373.  
  374.    extern int SLang_execute_function(char *);
  375.    /* Call S-Lang function p1.  Returns 0 if the function is not defined 
  376.     * and 1 if it is.
  377.     */
  378.  
  379.    extern char *SLang_find_name(char *);
  380.    /* Return a pointer to p1 in table if it is defined.  Returns NULL
  381.     * otherwise.  This is useful when one wants to avoid redundant strings. 
  382.     */
  383.  
  384.    extern char *SLang_rpn_interpret(char *);
  385.    /* Interpret string as reverse polish notation */
  386.  
  387.    extern void SLang_doerror(char *);
  388.    /* set SLang_Error and display p1 as error message */
  389.    
  390.    extern SLuser_Object_Type *SLang_add_array(char *, long *, 
  391.                           int, int, int, int, 
  392.                           unsigned char, unsigned char);
  393.    /* This function has not been tested thoroughly yet.  Its purpose is to 
  394.     * allow a S-Lang procedure to access a C array. For example, suppose that 
  395.     * you have an array of 100 ints defined as:
  396.     *  
  397.     *  int c_array[100];
  398.     *
  399.     * By calling something like:
  400.     *
  401.     *   SLang_add_array ("array_name", (long *) c_array, 1, 100, 0, 0,
  402.     *            'i', SLANG_IVARIABLE);
  403.     *
  404.     * the array can be accessed by the name 'array_name'.  This function 
  405.     * returns -1 upon failure.  The 3rd argument specifies the dimension 
  406.     * of the array, the 4th, and 5th arguments specify how many elements
  407.     * there are in the x,y, and z directions.  The last argument must 
  408.     * be one of: 
  409.     * 
  410.     *        SLANG_IVARIABLE:  indicates array is writable
  411.     *        SLANG_RVARIABLE:  indicates array is read only
  412.     * 
  413.     * Returns NULL upon failure.
  414.     */
  415.  
  416.  
  417. extern int SLang_free_array_handle (int);
  418. /* This routine may be called by application to free array handle created by 
  419.  * the application.  Returns 0 upon success, -1 if the handle is invalid and
  420.  * -2 if the handle is not associated with a C array.
  421.  */
  422.  
  423.    extern char *SLang_extract_list_element(char *, int *, int*);
  424.    extern void SLexpand_escaped_string (register char *, register char *, 
  425.                     register char *);
  426.  
  427. extern SLang_Name_Type *SLang_get_function (char *);
  428. /* The parameter is the name of a user defined S-Lang function.  This 
  429.  * routine returns NULL if the function does not exist or it returns the
  430.  * a pointer to it in an internal S-Lang table.  This pointer can be used
  431.  * by 'SLexecute_function' to call the function directly from C.
  432.  */
  433.   
  434. extern void SLexecute_function(SLang_Name_Type *);
  435. /* This function allows an application to call a S-Lang function from within
  436.  * the C program.  The parameter must be non-NULL and must have been 
  437.  * previously obtained by a call to 'SLang_get_function'.
  438.  */
  439.  
  440. extern char *SLmake_string (char *);
  441. extern char *SLmake_nstring (char *, int);
  442. /* Returns a null terminated string made from the first n characters of the
  443.  * string.
  444.  */
  445.  
  446. extern int SLang_guess_type (char *);
  447. /* SLang tty interface */
  448. extern int SLtt_Baud_Rate;
  449. extern unsigned long SLtt_Num_Chars_Output;
  450.    
  451. #ifdef unix
  452. extern int SLang_TT_Baud_Rate;
  453. extern int SLang_TT_Read_FD;
  454. #endif
  455.    
  456. extern int SLang_init_tty (int, int, int);
  457. /* Initializes the tty for single character input.  The first parameter *p1
  458.  * is the value 0-255 to be used for the abort character.  If the second
  459.  * parameter p2 is non-zero, flow control is enabled.  If the last 
  460.  * parmeter p3 is zero, output processing is NOT turned on.  A value of 
  461.  * zero is required for the screen management routines.
  462.  * Returns 0 upon success.
  463.  * In addition, if SLang_TT_Baud_Rate == 0 when this function is called, 
  464.  * SLang will attempt to determine  the terminals baud rate.  As far as 
  465.  * the SLang library is concerned, if SLang_TT_Baud_Rate is less than or 
  466.  * equal to zero, the baud rate is effectively infinite.
  467.  */
  468.  
  469. extern void SLang_reset_tty (void);
  470. /* Resets tty to what it was prior to a call to SLang_init_tty */
  471. #ifdef unix
  472. extern void SLtty_set_suspend_state (int);
  473.    /* If non-zero argument, terminal driver will be told to react to the
  474.     * suspend character.  If 0, it will not.
  475.     */
  476. #endif
  477.  
  478. extern unsigned int SLang_getkey (void);
  479. /* reads a single key from the tty.  If the read fails, 0xFFFF is returned. */
  480. extern void SLang_ungetkey_string (unsigned char *, int);
  481. extern void SLang_buffer_keystring (unsigned char *, int);
  482. extern void SLang_ungetkey (unsigned char);
  483. extern void SLang_flush_input (void);
  484. extern int SLang_input_pending (int);
  485. extern int SLang_Abort_Char;
  486. /* The value of the character (0-255) used to trigger SIGINT */
  487. extern int SLang_Ignore_User_Abort;
  488. /* If non-zero, pressing the abort character will not result in USER_BREAK
  489.  * SLang_Error. */
  490.  
  491. extern void SLang_set_abort_signal (void (*)(int));
  492. /* If SIGINT is generated, the function p1 will be called.  If p1 is NULL
  493.  * the SLang_default signal handler is called.  This sets SLang_Error to 
  494.  * USER_BREAK.  I suspect most users will simply want to pass NULL.
  495.  */
  496.  
  497. extern volatile int SLKeyBoard_Quit;
  498. /* --------------- SLang_keymap interface ----------------------- */
  499.  
  500. typedef struct SLKeymap_Function_Type
  501.   {
  502.       char *name;
  503.       int (*f)(void);
  504.   }
  505. SLKeymap_Function_Type;
  506.  
  507. typedef struct SLang_Key_Type
  508.   {
  509.      unsigned char str[13];           /* key sequence */
  510.      VOID *f;                   /* function to invoke */
  511.      unsigned char type;           /* type of function */
  512.      struct SLang_Key_Type *next;      /* */
  513.   }
  514. SLang_Key_Type;
  515.  
  516. #define MAX_KEYMAP_NAME_LEN 8
  517. typedef struct SLKeyMap_List_Type
  518. {
  519.    char name[MAX_KEYMAP_NAME_LEN + 1];
  520.    SLang_Key_Type *keymap;
  521.    SLKeymap_Function_Type *functions;  /* intrinsic functions */
  522. }
  523. SLKeyMap_List_Type;
  524.  
  525. /* This is arbitrary but I have got to start somewhere */
  526. #ifdef msdos
  527. #define SLANG_MAX_KEYMAPS 10
  528. #else
  529. #define SLANG_MAX_KEYMAPS 30
  530. #endif
  531.  
  532. extern SLKeyMap_List_Type SLKeyMap_List[SLANG_MAX_KEYMAPS];   /* these better be inited to 0! */
  533.  
  534. #define SLKEY_F_INTERPRET 0x01
  535. #define SLKEY_F_INTRINSIC 0x02
  536.  
  537. extern char *SLang_process_keystring(char *);
  538. extern int SLang_define_key1(char *, VOID *, unsigned char, SLKeyMap_List_Type *);
  539. /* define key p1 in keymap p4 to invoke function p2.  If type p3 is given by
  540.  * SLKEY_F_INTRINSIC, p2 is an intrinsic function, else it is a string to be
  541.  * passed to the interpreter for evaluation.  The return value is important.
  542.  * It returns 0 upon success, -1 upon malloc error, and -2 if the key is 
  543.  * inconsistent.  SLang_Error is set upon error. */
  544.  
  545. extern int SLang_define_key(char *, char *, SLKeyMap_List_Type *);
  546. /* Like define_key1 except that p2 is a string that is to be associated with 
  547.  * a function in the functions field of p3.  This routine calls define_key1.
  548.  */
  549.  
  550. extern void SLang_undefine_key(char *, SLKeyMap_List_Type *);
  551.  
  552. extern SLKeyMap_List_Type *SLang_create_keymap(char *, SLKeyMap_List_Type *);
  553. /* create and returns a pointer to a new keymap named p1 created by copying
  554.  * keymap p2.  If p2 is NULL, it is up to the calling routine to initialize
  555.  * the keymap.
  556.  */
  557.  
  558. extern char *SLang_make_keystring(unsigned char *);
  559.  
  560. extern SLang_Key_Type *SLang_do_key(SLKeyMap_List_Type *, int (*)(void));
  561. /* read a key using keymap p1 with getkey function p2 */
  562.  
  563. extern VOID *SLang_find_key_function(char *, SLKeyMap_List_Type *);
  564. extern SLKeyMap_List_Type *SLang_find_keymap(char *);
  565.  
  566. extern int SLang_Last_Key_Char;
  567. extern int SLang_Key_TimeOut_Flag;
  568.  
  569. /* --------------- SLang_read_line interface ----------------------- */
  570.  
  571. typedef struct SLang_Read_Line_Type
  572. {
  573.    struct SLang_Read_Line_Type *prev, *next;
  574.    unsigned char *buf;
  575.    int buf_len;                   /* number of chars in the buffer */
  576.    int num;                   /* num and misc are application specific*/
  577.    int misc;
  578. } SLang_Read_Line_Type;
  579.  
  580. /* Maximum size of display */
  581. #define SLRL_DISPLAY_BUFFER_SIZE 256
  582.  
  583. typedef struct 
  584. {
  585.    SLang_Read_Line_Type *root, *tail, *last;
  586.    unsigned char *buf;               /* edit buffer */
  587.    int buf_len;                   /* sizeof buffer */
  588.    int point;                   /* current editing point */
  589.    int tab;                   /* tab width */
  590.    int len;                   /* current line size */
  591.    
  592.    /* display variables */
  593.    int edit_width;               /* length of display field */
  594.    int curs_pos;                   /* current column */
  595.    int start_column;               /* column offset of display */
  596.    int dhscroll;               /* amount to use for horiz scroll */
  597.    char *prompt;
  598.    
  599.    VOID *last_fun;               /* last function executed by rl */
  600.  
  601.    /* These two contain an image of what is on the display */
  602.    unsigned char upd_buf1[SLRL_DISPLAY_BUFFER_SIZE];
  603.    unsigned char upd_buf2[SLRL_DISPLAY_BUFFER_SIZE];
  604.    unsigned char *old_upd, *new_upd;   /* pointers to previous two buffers */
  605.    int new_upd_len, old_upd_len;       /* length of output buffers */
  606.    
  607.    SLKeyMap_List_Type *keymap;
  608.  
  609.    /* tty variables */
  610.    unsigned int flags;               /*  */
  611.    unsigned int (*getkey)(void);       /* getkey function -- required */
  612.    void (*tt_goto_column)(int);
  613.    void (*tt_insert)(char);
  614.    void (*update_hook)(unsigned char *, int, int);
  615.    /* The update hook is called with a pointer to a buffer p1 that contains
  616.     * an image of what the update hook is suppoed to produce.  The length 
  617.     * of the buffer is p2 and after the update, the cursor is to be placed
  618.     * in column p3.
  619.     */
  620. } SLang_RLine_Info_Type;
  621.  
  622. #ifdef linux_unicode
  623. typedef unsigned long SLang_Char_Type;
  624. #else
  625. typedef unsigned short SLang_Char_Type;
  626. #endif
  627. extern int SLtt_Unicode;
  628.  
  629. extern int SLang_RL_EOF_Char;
  630. #define SLRL_USE_ANSI 0x01
  631.  
  632. extern SLang_Read_Line_Type * SLang_rline_save_line (SLang_RLine_Info_Type *);
  633. extern int SLang_init_readline (SLang_RLine_Info_Type *);
  634. extern int SLang_read_line (SLang_RLine_Info_Type *);
  635. extern int SLang_rline_insert (char *);
  636. extern void SLrline_redraw (SLang_RLine_Info_Type *);   
  637. extern int SLang_Rline_Quit;
  638. /* ---------------------------------------------------------------------- */
  639.  
  640.  
  641. extern int SLang_extract_token(char **, char *, int);
  642. /* returns 0 upon failure and non-zero upon success.  The first parameter 
  643.  * is a pointer to the input stream which this function will bump along.  
  644.  * The second parameter is the buffer where the token is placed.  The third 
  645.  * parameter is used internally by the S-Lang library and should be 0 for
  646.  * user applications.
  647.  */
  648.  
  649. /* ----------------------------------------------------------------------- */
  650. /* Screen Output functions */
  651.  
  652. typedef unsigned long SLtt_Char_Type;
  653.  
  654. #define SLTT_BOLD_MASK    0x01000000
  655. #define SLTT_BLINK_MASK    0x02000000
  656. #define SLTT_ULINE_MASK    0x04000000
  657. #define SLTT_REV_MASK    0x08000000
  658. #define SLTT_ALTC_MASK  0x10000000
  659.  
  660. extern int SLtt_Screen_Rows;
  661. extern int SLtt_Screen_Cols;
  662. extern int SLtt_Term_Cannot_Insert;
  663. extern int SLtt_Term_Cannot_Scroll;
  664. extern int SLtt_Use_Ansi_Colors;
  665. extern int SLtt_Ignore_Beep;
  666. extern int SLtt_Try_Termcap;
  667. extern int SLtt_Has_Alt_Charset;
  668.    
  669. #if defined(VMS) || defined(unix)
  670. extern int SLtt_Blink_Mode;
  671. extern int SLtt_Use_Blink_For_ACS;
  672. extern int SLtt_Newline_Ok;
  673. #endif
  674.  
  675. #ifdef msdos
  676. extern int SLtt_Msdos_Cheap_Video;
  677. #endif
  678. extern void SLtt_set_alt_char_set (int);
  679. extern int SLtt_flush_output (void);
  680. extern void SLtt_set_scroll_region(int, int);
  681. extern void SLtt_reset_scroll_region(void);
  682. extern void SLtt_reverse_video (int);
  683. extern void SLtt_bold_video (void);
  684. extern void SLtt_begin_insert(void);
  685. extern void SLtt_end_insert(void);
  686. extern void SLtt_del_eol(void);
  687. extern void SLtt_goto_rc (int, int);
  688. extern void SLtt_delete_nlines(int);
  689. extern void SLtt_delete_char(void);
  690. extern void SLtt_erase_line(void);
  691. extern void SLtt_normal_video(void);
  692. extern void SLtt_cls(void);
  693. extern void SLtt_beep(void);
  694. extern void SLtt_reverse_index(int);
  695. extern void SLtt_smart_puts(SLang_Char_Type *, SLang_Char_Type *, int, int);
  696. extern void SLtt_write_string (char *);
  697. extern void SLtt_putchar(char);
  698. extern void SLtt_init_video (void);
  699. extern void SLtt_reset_video (void);
  700. extern void SLtt_want_unicode (void);
  701. extern unsigned short SLtt_fix_unicode (unsigned short);
  702. extern void SLtt_get_terminfo(void);
  703. extern int SLtt_set_cursor_visibility (int);
  704. #if defined(VMS) || defined(unix)
  705. # ifndef __GO32__
  706. extern void SLtt_enable_cursor_keys(void);
  707. extern void SLtt_set_term_vtxxx(int *);
  708. extern void SLtt_set_color_esc (int, char *);
  709. extern void SLtt_wide_width(void);
  710. extern void SLtt_narrow_width(void);
  711. #  ifdef unix
  712.    extern char *SLtt_tgetstr (char *);
  713.    extern int SLtt_tgetnum (char *);
  714.    extern int SLtt_tgetflag (char *);
  715.    extern char *SLtt_tigetstr (char *, char **);
  716.    extern char *SLtt_tigetent (char *);
  717.    extern int SLtt_tigetnum (char *, char **);
  718.    extern int SLtt_tigetflag (char *, char **);
  719. #  endif
  720. # endif
  721. #endif
  722. extern void SLtt_set_color_object (int, SLtt_Char_Type);
  723. extern void SLtt_set_color (int, char *, char *, char *);
  724. extern void SLtt_set_mono (int, char *, SLtt_Char_Type);
  725. extern void SLtt_add_color_attribute (int, SLtt_Char_Type);
  726.      
  727. /*-------------------------------------------------------------------------
  728.  * Preprocessor
  729.  */
  730. typedef struct 
  731. {
  732.    int this_level;
  733.    int exec_level;
  734.    int prev_exec_level;
  735.    char preprocess_char;
  736.    char comment_char;
  737. }
  738. SLPreprocess_Type;
  739.  
  740. extern int SLprep_open_prep (SLPreprocess_Type *);
  741. extern void SLprep_close_prep (SLPreprocess_Type *);
  742. extern int SLprep_line_ok (char *, SLPreprocess_Type *);
  743.    extern int SLdefine_for_ifdef (char *);
  744.    /* Adds a string to the SLang #ifdef preparsing defines. SLang already
  745.       defines MSDOS, UNIX, and VMS on the appropriate system. */
  746.       
  747.    
  748.    
  749.  
  750. /* ----------------------------------------------------------------------- */
  751. /* Screen management functions */
  752.  
  753. #include <stdarg.h>
  754. extern void SLsmg_fill_region (int, int, int, int, unsigned char);
  755. #ifndef pc_system
  756. extern void SLsmg_set_char_set (int);
  757. extern int SLsmg_Scroll_Hash_Border;
  758. #endif
  759. extern void SLsmg_suspend_smg (void);
  760. extern void SLsmg_resume_smg (void);
  761. extern void SLsmg_erase_eol (void);
  762. extern void SLsmg_gotorc (int, int);
  763. extern void SLsmg_erase_eos (void);
  764. extern void SLsmg_reverse_video (void);
  765. extern void SLsmg_set_color (int);
  766. extern void SLsmg_normal_video (void);
  767. extern void SLsmg_printf (char *, ...);
  768. extern void SLsmg_vprintf (char *, va_list);
  769. extern void SLsmg_write_string (char *);
  770. extern void SLsmg_write_nstring (char *, int);
  771. extern void SLsmg_write_char (char);
  772. extern void SLsmg_write_nchars (char *, int);
  773. extern void SLsmg_write_wrapped_string (char *, int, int, int, int, int);
  774. extern void SLsmg_cls (void);
  775. extern void SLsmg_refresh (void);
  776. extern void SLsmg_touch_lines (int, int);
  777. extern int SLsmg_init_smg (void);
  778. extern void SLsmg_reset_smg (void);
  779. extern SLang_Char_Type SLsmg_char_at(void);
  780. extern void SLsmg_set_screen_start (int *, int *);
  781. extern void SLsmg_draw_hline (int);
  782. extern void SLsmg_draw_vline (int);
  783. extern void SLsmg_draw_object (int, int, unsigned char);
  784. extern void SLsmg_draw_box (int, int, int, int);
  785. extern void SLsmg_draw_double_hline (int);
  786. extern void SLsmg_draw_double_vline (int);
  787. extern void SLsmg_draw_double_box (int, int, int, int);
  788. extern void SLsmg_draw_unicode (int, int, unsigned short);
  789. extern void SLsmg_write_unicode (unsigned short);
  790. extern int SLsmg_get_column(void);
  791. extern int SLsmg_get_row(void);
  792. extern int SLsmg_Display_Eight_Bit;
  793. extern int SLsmg_Tab_Width;
  794.  
  795. #ifdef pc_system
  796. # define SLSMG_HLINE_CHAR    0xC4
  797. # define SLSMG_VLINE_CHAR    0xB3
  798. # define SLSMG_ULCORN_CHAR    0xDA
  799. # define SLSMG_URCORN_CHAR    0xBF
  800. # define SLSMG_LLCORN_CHAR    0xC0
  801. # define SLSMG_LRCORN_CHAR    0xD9
  802. /* There are several to choose from: 0xB0, 0xB1, and 0xB2 */
  803. # define SLSMG_CKBRD_CHAR    0xB0
  804. #else
  805. # define SLSMG_HLINE_CHAR    'q'
  806. # define SLSMG_VLINE_CHAR    'x'
  807. # define SLSMG_ULCORN_CHAR    'l'
  808. # define SLSMG_URCORN_CHAR    'k'
  809. # define SLSMG_LLCORN_CHAR    'm'
  810. # define SLSMG_LRCORN_CHAR    'j'
  811. # define SLSMG_CKBRD_CHAR    'a'
  812. # define SLSMG_RTEE_CHAR    'u'
  813. # define SLSMG_LTEE_CHAR    't'
  814. # define SLSMG_UTEE_CHAR    'w'
  815. # define SLSMG_DTEE_CHAR    'v'
  816. # define SLSMG_CROSS_CHAR    'n'
  817. #endif
  818. /* Just some characters from Unicode */
  819. # define SLUNI_HLINE_CHAR    0x2500
  820. # define SLUNI_VLINE_CHAR    0x2502
  821. # define SLUNI_ULCORN_CHAR    0x250C
  822. # define SLUNI_URCORN_CHAR    0x2510
  823. # define SLUNI_LLCORN_CHAR    0x2514
  824. # define SLUNI_LRCORN_CHAR    0x2518
  825. # define SLUNI_CKBRD_CHAR    0x2591
  826. # define SLUNI_RTEE_CHAR    0x2524
  827. # define SLUNI_LTEE_CHAR    0x251C
  828. # define SLUNI_UTEE_CHAR    0x252C
  829. # define SLUNI_DTEE_CHAR    0x2534
  830. # define SLUNI_CROSS_CHAR    0x253C
  831. # define SLUNI_DHLINE_CHAR    0x2550
  832. # define SLUNI_DVLINE_CHAR    0x2551
  833. # define SLUNI_DULCORN_CHAR    0x2554
  834. # define SLUNI_DURCORN_CHAR    0x2557
  835. # define SLUNI_DLLCORN_CHAR    0x255A
  836. # define SLUNI_DLRCORN_CHAR    0x255D
  837. # define SLUNI_DRTEE_CHAR    0x2563
  838. # define SLUNI_DLTEE_CHAR    0x2560
  839. # define SLUNI_DUTEE_CHAR    0x2566
  840. # define SLUNI_DDTEE_CHAR    0x2569
  841. # define SLUNI_DCROSS_CHAR    0x256C
  842. # define SLUNI_DSRTEE_CHAR    0x2562
  843. # define SLUNI_DSLTEE_CHAR    0x255F
  844. # define SLUNI_DSUTEE_CHAR    0x2564
  845. # define SLUNI_DSDTEE_CHAR    0x2567
  846. # define SLUNI_SDRTEE_CHAR    0x2561
  847. # define SLUNI_SDLTEE_CHAR    0x255E
  848. # define SLUNI_SDUTEE_CHAR    0x2565
  849. # define SLUNI_SDDTEE_CHAR    0x2568
  850. /* ----------------------------------------------------------------------- */
  851.  
  852. /* subtypes of literal (static) and data (dynamic)*/
  853. #define VOID_TYPE    1
  854. #define INT_TYPE     2
  855. #ifdef FLOAT_TYPE
  856. #undef FLOAT_TYPE
  857. #define FLOAT_TYPE    3
  858. #endif
  859. #define CHAR_TYPE    4
  860. #define INTP_TYPE    5
  861. #define SLANG_OBJ_TYPE    6
  862.  
  863. /* Everything above string should correspond to a pointer in the object 
  864.  * structure.  See do_binary (slang.c) for exploitation of this fact.
  865.  */
  866. #define STRING_TYPE     10
  867. /* Array type MUST be the smallest number for SLuser_Object_Type structs */
  868. #define ARRAY_TYPE    20
  869. /* I am reserving values greater than or equal to user applications.  The
  870.  * first 99 are used for S-Lang.
  871.  */
  872.  
  873.  
  874. #define SLANG_LVARIABLE    0x01
  875. #define SLANG_LOGICAL    0x02
  876. #define SLANG_BINARY    0x03
  877. /* #define SLANG_LINTRINSIC    0x04
  878.  * #define SLANG_LFUNCTION     0x05 */
  879. #define SLANG_INTRINSIC     0x06
  880. #define SLANG_FUNCTION      0x07
  881. #define SLANG_LITERAL    0x08           /* constant objects */
  882. #define SLANG_BLOCK      0x09
  883. #define SLANG_DIRECTIVE    0x0A
  884. #define SLANG_UNARY    0x0B
  885. #define SLANG_LUNARY    0x0C
  886.  
  887. #define SLANG_GVARIABLE     0x0D
  888. #define SLANG_IVARIABLE     0x0E           /* intrinsic variables */
  889. /* Note!!! For Macro MAKE_VARIABLE below to work, SLANG_IVARIABLE Must
  890.    be 1 less than SLANG_RVARIABLE!!! */
  891. #define SLANG_RVARIABLE    0x0F           /* read only variable */
  892.  
  893. /* These 3 MUST be in this order too ! */
  894. #define SLANG_RETURN    0x10
  895. #define SLANG_BREAK    0x11
  896. #define SLANG_CONTINUE    0x12
  897.  
  898.  
  899. #define SLANG_EXCH    0x13
  900. #define SLANG_LABEL    0x14
  901. #define SLANG_LOBJPTR    0x15
  902. #define SLANG_GOBJPTR    0x16
  903. #define SLANG_X_ERROR    0x17
  904. /* These must be in this order */
  905. #define SLANG_X_USER0    0x18
  906. #define SLANG_X_USER1    0x19
  907. #define SLANG_X_USER2    0x1A
  908. #define SLANG_X_USER3    0x1B
  909. #define SLANG_X_USER4    0x1C
  910.  
  911.  
  912. #define SLANG_DATA    0x30           /* real objects which may be destroyed */
  913.  
  914.  
  915. /* Binary and Unary Subtypes */
  916. /* This group may be overloaded. */
  917. #define SLANG_PLUS    1
  918. #define SLANG_MINUS    2
  919. #define SLANG_TIMES    3
  920. #define SLANG_DIVIDE    4
  921. #define SLANG_EQ        5
  922. #define SLANG_NE        6
  923. #define SLANG_GT        7
  924. #define SLANG_GE        8
  925. #define SLANG_LT        9
  926. #define SLANG_LE        10
  927.  
  928. /* UNARY subtypes  (may be overloaded) */
  929. #define SLANG_ABS    11
  930. #define SLANG_SIGN    12
  931. #define SLANG_SQR    13
  932. #define SLANG_MUL2    14
  933. #define SLANG_CHS    15
  934.  
  935. /* error codes, severe errors are less than 0 */
  936. #define SL_INVALID_PARM        -6
  937. #define SL_MALLOC_ERROR        -5
  938. #define INTERNAL_ERROR        -4
  939. #define UNKNOWN_ERROR        -3
  940. #define STACK_OVERFLOW        -1
  941. #define STACK_UNDERFLOW        -2
  942. #define INTRINSIC_ERROR        1
  943. /* Intrinsic error is an error generated by intrinsic functions */
  944. #define USER_BREAK        2
  945. #define UNDEFINED_NAME        3
  946. #define SYNTAX_ERROR        4
  947. #define DUPLICATE_DEFINITION    5
  948. #define TYPE_MISMATCH        6
  949. #define READONLY_ERROR        7
  950. #define DIVIDE_ERROR        8
  951. /* object could not be opened */
  952. #define SL_OBJ_NOPEN        9
  953. /* unknown object */
  954. #define SL_OBJ_UNKNOWN        10
  955.  
  956. extern char *SLang_Error_Message;
  957.  
  958. extern void SLadd_name(char *, long, unsigned char, unsigned char);
  959. extern void SLadd_at_handler (long *, char *);
  960.  
  961. #define SLANG_MAKE_ARGS(out, in) ((unsigned char)(out) | ((unsigned short) (in) << 4))
  962.  
  963. #ifdef SLANG_STATS
  964.  
  965. #define MAKE_INTRINSIC(n, f, out, in)        \
  966.     {0, n, (out | (in << 4)), SLANG_INTRINSIC, (long) f}
  967.        
  968. #define MAKE_VARIABLE(n, v, t, r)     \
  969.     {0, n, t, (SLANG_IVARIABLE + r, (long) v}
  970.  
  971. #else
  972. #define MAKE_INTRINSIC(n, f, out, in)        \
  973.     {n, (out | (in << 4)), SLANG_INTRINSIC, (long) f}
  974.        
  975. #define MAKE_VARIABLE(n, v, t, r)     \
  976.     {n, t, (SLANG_IVARIABLE + r), (long) v}
  977. #endif
  978.  
  979. #define SLANG_END_TABLE  MAKE_INTRINSIC("", 0, 0, 0)
  980.  
  981. /* Uppercase, lowercase macros */
  982. extern void SLang_define_case(int *, int *);
  983. extern void SLang_init_case_tables (void);
  984.  
  985. extern unsigned char Chg_UCase_Lut[256];
  986. extern unsigned char Chg_LCase_Lut[256];
  987. #define UPPER_CASE(x) (Chg_UCase_Lut[(unsigned char) (x)])
  988. #define LOWER_CASE(x) (Chg_LCase_Lut[(unsigned char) (x)])
  989. #define CHANGE_CASE(x) (((x) == Chg_LCase_Lut[(unsigned char) (x)]) ?\
  990.             Chg_UCase_Lut[(unsigned char) (x)] : Chg_LCase_Lut[(unsigned char) (x)])
  991.  
  992.  
  993. typedef struct
  994. {
  995.    unsigned char *pat;               /* regular expression pattern */
  996.    unsigned char *buf;               /* buffer for compiled regexp */
  997.    int buf_len;                   /* length of buffer */
  998.    int case_sensitive;               /* 1 if match is case sensitive  */
  999.    int must_match;               /* 1 if line must contain substring */
  1000.    int must_match_bol;               /* true if it must match beginning of line */
  1001.    unsigned char must_match_str[16];   /* 15 char null term substring */
  1002.    int osearch;                   /* 1 if ordinary search suffices */
  1003.    int min_length;               /* minimum length the match must be */
  1004.    int beg_matches[10];               /* offset of start of \( */
  1005.    int end_matches[10];               /* length of nth submatch
  1006.                     * Note that the entire match corresponds
  1007.                     * to \0 
  1008.                     */
  1009.    int offset;                   /* offset to be added to beg_matches */
  1010. } SLRegexp_Type;
  1011.  
  1012. extern unsigned char *SLang_regexp_match(unsigned char *, int, SLRegexp_Type *);
  1013. extern int SLang_regexp_compile (SLRegexp_Type *);
  1014.  
  1015. #ifdef SLKEYMAPS
  1016. /* Keymap routines and definitions */
  1017. typedef
  1018. {
  1019.    char *name;
  1020.    int (*f) (void);
  1021. }
  1022. SLKeymap_Fun_Type;
  1023. #endif
  1024.  
  1025.  
  1026. /* ------------------------------------------------------------------------ */
  1027. /* cmd line definitions */
  1028.  
  1029. #define SLCMD_MAX_ARGS 10
  1030. #ifdef __WATCOMC__
  1031.        struct SLcmd_Cmd_Type; /* Pre-declaration is needed for the watcom c++ compiler */
  1032. #endif
  1033. typedef struct SLcmd_Cmd_Table_Type
  1034. {
  1035.    struct SLcmd_Cmd_Type *table;
  1036.    int argc;
  1037.    char *string_args[SLCMD_MAX_ARGS];
  1038.    int int_args[SLCMD_MAX_ARGS];
  1039.    FLOAT float_args[SLCMD_MAX_ARGS];
  1040. } SLcmd_Cmd_Table_Type;
  1041.  
  1042.  
  1043. typedef struct SLcmd_Cmd_Type
  1044. {
  1045.    int (*cmdfun)(int, struct SLcmd_Cmd_Table_Type *);
  1046.    char cmd[32];
  1047.    char arg_type[SLCMD_MAX_ARGS];
  1048. } SLcmd_Cmd_Type;
  1049.  
  1050. extern int SLcmd_execute_string (char *, SLcmd_Cmd_Table_Type *);
  1051. /* ------------------------------------------------------------------------ */
  1052.  
  1053. /* search functions */
  1054.  
  1055. typedef struct
  1056. {
  1057.    int cs;                   /* case sensitive */
  1058.    unsigned char key[256];
  1059.    int ind[256];
  1060.    int key_len;
  1061.    int dir;
  1062. } SLsearch_Type;
  1063.  
  1064. extern int SLsearch_init (char *, int, int, SLsearch_Type *);
  1065. /* This routine must first be called before any search can take place. 
  1066.  * The second parameter specifies the direction of the search: greater than 
  1067.  * zero for a forwrd search and less than zero for a backward search.  The 
  1068.  * third parameter specifies whether the search is case sensitive or not.
  1069.  * The last parameter is a pointer to a structure that is filled by this 
  1070.  * function and it is this structure that must be passed to SLsearch.
  1071.  */
  1072.  
  1073. unsigned char *SLsearch (unsigned char *, unsigned char *, SLsearch_Type *);
  1074. /* To use this routine, you must first call 'SLsearch_init'.  Then the first 
  1075.  * two parameters p1 and p2 serve to define the region over which the search
  1076.  * is to take place.  The third parameter is the structure that was previously
  1077.  * initialized by SLsearch_init.
  1078.  * 
  1079.  * The routine returns a pointer to the match if found otherwise it returns 
  1080.  * NULL.
  1081.  */
  1082.  
  1083. #ifdef __cplusplus
  1084. }
  1085. #endif
  1086.  
  1087. /* _davis_slang_h_ */
  1088. #endif 
  1089.